import store from '@/store'
import router from './router'
const whiteList = ['/login', '/404']
router.beforeEach(function (to, from, next) {
  // console.log(store.getters.token)
  if (store.state.user.token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
      // 用户信息不存在 才去获取一次  防止重复获取
      // if (!store.state.user.userInfo.userId) {
      //   store.dispatch('user/getUserInfo')
      // }
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
